/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 fireball.h

	$Header: /heroes4/fireball.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( FIREBALL_H_INCLUDED )
#define FIREBALL_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "combat_actor_model_cache.h"
#include "combat_creature_list.h"
#include "combat_spell.h"
#include "map_point.h"

struct t_ai_area_target;
class	t_ai_area_target_list;

// ----------------------------------------------------------
// base class for area effect spells
// ----------------------------------------------------------
class t_area_spell : public t_combat_spell
{
public:
	t_area_spell( t_battlefield& battlefield, t_spell spell );

	virtual void					ai_cast_spell();
	virtual bool					begin_casting();
	virtual bool					can_cast( t_screen_point const& point ) const;
	virtual void					execute( t_combat_creature& caster );
	virtual void					execute_mirror_spell( t_combat_creature_ptr creature, int power );
	virtual t_combat_ai_action_list	generate_combat_ai_action_list(t_combat_ai &owner);
	virtual t_mouse_window*			mouse_move( t_screen_point const& point,
									    std::string& help_text );
	virtual bool					left_click( t_screen_point const& point );

protected:
	struct t_impact_data;

	virtual void			cast( t_combat_creature_ptr caster, 
							      t_map_point_2d        target_square,
							      int				    power,
								  bool					is_mirror ) = 0;
	bool					can_cast( t_map_point_2d const& center ) const;
	void					evaluate_targets( t_ai_area_target_list&   list ) const;
	void					evaluate_overlap( t_combat_creature const&	primary,
											  t_combat_creature const&	secondary,
											  t_ai_area_target_list&	list ) const;
	void					evaluate_target( t_map_point_2d const& target_cell, 
											 t_ai_area_target_list& list ) const;
	bool					get_map_point( t_screen_point const& point, 
							               t_map_point_2d&		center ) const;
	virtual int				get_radius() const;
	double					get_square_value( t_map_point_2d const& target ) const;
	t_combat_creature_list	get_targets( t_combat_creature_ptr caster, 
									     t_map_point_2d const& point ) const;
	void					impact( t_combat_creature_ptr caster, 
		                            t_map_point_2d        target_point, 
									t_impact_data         impact_data );
	void					launch( t_missile_type		  missile_type, 
							        t_combat_creature_ptr caster, 
							        t_map_point_2d		  target_square, 
									int					  power,
									bool				  is_mirror);
	void					place_spell( t_combat_actor_model_ptr model, 
							             t_map_point_2d target_point,
										 bool			is_mirror );
	virtual void			show_impact( t_map_point_2d target_point, bool is_mirror ) = 0;

	t_map_point_2d m_target_square;
};

// ----------------------------------------------------------
// handle fireball spell
// ----------------------------------------------------------
class t_fireball : public t_area_spell
{
public:
	t_fireball( t_battlefield& battlefield, t_spell spell);

	virtual bool			cast_on( t_combat_creature_ptr caster,
		                             t_combat_creature_ptr target, 
									 int power,
									 bool is_mirror );
	virtual double			get_cancel_weight( t_combat_creature const& target ) const;
	virtual double			ai_weight( t_combat_creature const& target ) const;
protected:
	virtual void		   cast( t_combat_creature_ptr caster, 
		                         t_map_point_2d        target_square,
					             int				   power,
								 bool				   is_mirror );
	void				   place_fireball( t_map_point_2d point, bool is_mirror );
	virtual void           show_impact( t_map_point_2d target_point, bool is_mirror );
};

#endif // FIREBALL_H_INCLUDED